package com.ss.android.newmedia.message;

import android.content.Context;
import android.text.TextUtils;
import android.util.Pair;
import com.bytedance.common.plugin.interfaces.pushmanager.MessageConstants;
import com.bytedance.common.plugin.interfaces.pushmanager.PushChannelHelper;
import com.bytedance.common.plugin.interfaces.pushmanager.PushPluginDepend;
import com.bytedance.common.plugin.interfaces.pushmanager.setting.PushSetting;
import com.bytedance.common.utility.b.ThreadPlus;
import com.bytedance.common.utility.Logger;
import com.ss.android.common.util.ToolUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.json.JSONObject;

final class p extends ThreadPlus {
    private final o b;
    private final Context a;

    p(o arg1, Context arg2) {
        this.b = arg1;
        this.a = arg2;
    }

    public final void run() {
        Map v1 = s.a(this.a);
        String v2 = "notice";
        String v0 = PushSetting.getInstance().isPushNotifyEnable() ? "0" : "1";
        v1.put(v2, v0);
        v1.put("system_notify_status", ToolUtils.g(this.a));
        v0 = s.a(MessageConstants.UPDATE_SENDER_URL, v1);
        try {
            Logger.d("PushConfigHelper", "开始请求通道");
            ArrayList v1_1 = new ArrayList();
            ((List)v1_1).add(new Pair("push_sdk", PushChannelHelper.getInstance().buildApplogHeader().toString()));
            v0 = PushPluginDepend.inst().post(v0, ((List)v1_1));
            if(Logger.debug()) {
                Logger.d("PushConfigHelper", "handleAppLogUpdate run() called response = " + v0);
            }

            if(TextUtils.isEmpty(((CharSequence)v0))) {
            }else {
                JSONObject v1_2 = new JSONObject(v0);
                if (!"success".equals(v1_2.optString("message"))) {
                } else {
                    v0 = v1_2.optString("allow_push_list");
                    if (TextUtils.isEmpty(((CharSequence) v0))) {
                    } else {
                        o.a(this.b, o.a(this.b), v0);
                        o.b(this.b);
                        PushSetting.getInstance().setLastGetUpdateSenderTimeMil(System.currentTimeMillis());
                        return;
                    }
                }
            }
        } catch(Exception v0_1) {
            if(!Logger.debug()) {
            }else {
                Logger.e("PushConfigHelper", "run: UPDATE_SENDER_URL e = " + v0_1.getMessage());
                v0_1.printStackTrace();
            }
        }

        Logger.d("PushConfigHelper", "访问 UPDATE_SENDER_URL 失败");
        o.b(this.b);
        o.a(this.b, o.a(this.b), PushSetting.getInstance().getPushChannelsJsonArray());
    }
}

